<script setup>
import { getStudentStatusListApi } from '@/api/studentStatus'
import { ref } from 'vue'

const statusList = ref([])

// 获取状态对应的文字和样式
const getStatusInfo = (status) => {
  const statusMap = {
    0: { text: '已申请', color: '#909399' },
    1: { text: '待面试', color: '#E6A23C' },
    2: { text: '已入职', color: '#67C23A' },
    3: { text: '已提交材料', color: '#409EFF' }
  }
  return statusMap[status] || { text: '未知状态', color: '#909399' }
}

// 获取面试结果对应的文字和样式
const getInterviewResult = (result) => {
  const resultMap = {
    0: { text: '待面试', color: '#E6A23C' },
    1: { text: '未通过', color: '#F56C6C' },
    2: { text: '已通过', color: '#67C23A' }
  }
  return resultMap[result] || { text: '--', color: '#909399' }
}

// 名字脱敏处理
const maskName = (name) => {
  if (!name) return ''
  if (name.length === 2) {
    return name[0] + '*'
  }
  return name[0] + '*' + name.slice(2)
}

async function getStudentStatusList() {
  const res = await getStudentStatusListApi()
  statusList.value = res.data.slice(0, 5)
}

getStudentStatusList()
</script>

<template>
  <div class="list-wrapper">
    <div class="title">最新学生动态</div>
    <div class="table">
      <div class="list-header">
        <div class="col name-col">姓名</div>
        <div class="col job-col">应聘职位</div>
        <div class="col company-col">公司名称</div>
        <div class="col status-col">状态</div>
      </div>
      <div class="student-list">
        <div v-for="item in statusList" :key="item.id" class="student-item">
          <div class="col name-col">{{ maskName(item.name) }}</div>
          <div class="col job-col">{{ item.jobName }}</div>
          <div class="col company-col">{{ item.enterpriseName }}</div>
          <div class="col status-col">
            <span class="status-tag" :style="{ color: getStatusInfo(item.status).color }">
              {{ getStatusInfo(item.status).text }}
            </span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.list-wrapper {
  width: 100%;
  height: 100%;
  background-color: #fff;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);

  .title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
    color: #2c3e50;
    padding-left: 12px;
    border-left: 4px solid #409eff;
    display: flex;
    align-items: center;

    &::after {
      content: '';
      flex: 1;
      height: 1px;
      background: linear-gradient(to right, #e0e6ed, transparent);
      margin-left: 16px;
    }
  }

  .table {
    .list-header {
      display: flex;
      align-items: center;
      padding: 12px 16px;
      background-color: #f5f7fa;
      border-radius: 4px;
      margin-bottom: 8px;
      font-weight: 500;
      color: #606266;
    }

    .student-list {
      .student-item {
        display: flex;
        align-items: center;
        padding: 16px;
        border-bottom: 1px solid #ebeef5;
        transition: all 0.3s;

        &:hover {
          background-color: #f5f7fa;
        }

        &:last-child {
          border-bottom: none;
        }
      }
    }

    // 列宽设置
    .col {
      font-size: 14px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .name-col {
      width: 120px;
      padding-right: 20px;
    }

    .job-col {
      flex: 1;
      padding-right: 20px;
      min-width: 200px;
    }

    .company-col {
      width: 200px;
      padding-right: 20px;
    }

    .status-col {
      width: 100px;
      text-align: center;

      .status-tag {
        font-weight: 500;
      }
    }
  }
}
</style>
